#include "CharDistribution.h"
#include "GB2312Freq.tab"
#include "nsMemory.h"

#define SURE_YES 0.99f
#define SURE_NO  0.01f

//return confidence base on received data
float CharDistributionAnalysis::GetConfidence( void ) {
  if( mTotalChars <= 0 || mFreqChars <= mDataThreshold ) {
    return SURE_NO;
  }
  if( mTotalChars != mFreqChars ) {
    float r = mFreqChars / ( ( mTotalChars - mFreqChars ) * mTypicalDistributionRatio );
    if( r < SURE_YES ) {
      return r;
    }
  }
  return SURE_YES;
}

GB2312DistributionAnalysis::GB2312DistributionAnalysis() {
  mCharToFreqOrder = GB2312CharToFreqOrder;
  mTableSize = NS_ARRAY_LENGTH( GB2312CharToFreqOrder );
  mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO;
}
